<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="myUtil.materialCheck" %>
<%@ page import="java.sql.*" %>
<html>
<head>
    <title>person_save</title>
</head>
<body>
<%
    String I = request.getParameter("id");
    int i = Integer.parseInt(I);
    String itemId = request.getParameter("itemId");
    String itemName = request.getParameter("itemName");
    String itemClasses = request.getParameter("itemClasses");
    String vendorName = request.getParameter("vendorName");
    String site = request.getParameter("site");
    String inboundTime = request.getParameter("inboundTime");
    String contact = request.getParameter("contact");
    String phoneNumber = request.getParameter("phoneNumber");
    String itemDescription = request.getParameter("itemDescription");
    if (materialCheck.checkNumber(itemId) && materialCheck.checkS(itemName) && materialCheck.checkS(itemClasses) &&
            materialCheck.checkS(vendorName) && materialCheck.checkS(site) && materialCheck.checkS(inboundTime) &&
            materialCheck.checkS(contact) &&materialCheck.checkPhoneNumber(phoneNumber)) {
        Connection conn = (Connection)session.getAttribute("Connection");
        //根据数据id进行数据更新
        String sql = String.format("update material set itemId=?, itemName=?, itemClasses=?, vendorName=?, site=?, inboundTime=?, contact=?, phoneNumber=?, itemDescription=? where id=%d", i);
        PreparedStatement preparedStatement = conn.prepareStatement(sql);

        preparedStatement.setString(1, itemId);
        preparedStatement.setString(2, itemName);
        preparedStatement.setString(3, itemClasses);
        preparedStatement.setString(4, vendorName);
        preparedStatement.setString(5, site);
        preparedStatement.setString(6, inboundTime);
        preparedStatement.setString(7, contact);
        preparedStatement.setString(8, phoneNumber);
        preparedStatement.setString(9,itemDescription);

        preparedStatement.executeUpdate();
        response.sendRedirect("material_list.jsp");
    } else {
        request.getRequestDispatcher("material_edit.jsp").forward(request, response);
    }

%>
</body>
</html>
